workspace(name = "org_torch_blade")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("//bazel/torch_mlir:repo.bzl", "blade_http_archive")

http_archive(
    name = "com_github_bazelbuild_buildtools",
    sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
    strip_prefix = "buildtools-4.2.2",
    urls = [
        "https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz",
    ],
)

http_archive(
    name = "bazel_skylib",
    sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
    urls = [
        "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
    ],
)

http_archive(
    name = "rules_python",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_python/releases/download/0.4.0/rules_python-0.4.0.tar.gz",
        "https://github.com/bazelbuild/rules_python/releases/download/0.4.2/rules_python-0.4.0.tar.gz",
    ],
)

#`pybind11_bazel`
# See https://github.com/pybind/pybind11_bazel
http_archive(
    name = "pybind11_bazel",
    sha256 = "a5666d950c3344a8b0d3892a88dc6b55c8e0c78764f9294e806d69213c03f19d",
    strip_prefix = "pybind11_bazel-26973c0ff320cb4b39e45bc3e4297b82bc3a6c09",
    urls = [
        "http://pai-blade.oss-accelerate.aliyuncs.com/build_deps/pybind11_bazel/26973c0ff320cb4b39e45bc3e4297b82bc3a6c09.zip",
        "https://github.com/pybind/pybind11_bazel/archive/26973c0ff320cb4b39e45bc3e4297b82bc3a6c09.zip",
    ],
)

http_archive(
    name = "googltest",
    sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2",
    strip_prefix = "googletest-release-1.12.1",
    urls = ["https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz"],
)

http_archive(
    name = "rules_foreign_cc",
    sha256 = "33a5690733c5cc2ede39cb62ebf89e751f2448e27f20c8b2fbbc7d136b166804",
    strip_prefix = "rules_foreign_cc-0.5.1",
    urls = [
        "http://pai-blade.oss-accelerate.aliyuncs.com/build_deps/rules_foreign_cc/0.5.1.tar.gz",
        "https://github.com/bazelbuild/rules_foreign_cc/archive/0.5.1.tar.gz",
    ],
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies(
    register_built_tools = False,  # do not build cmake/make from source,
    register_default_tools = False,  # nor download from official site,
    register_preinstalled_tools = True,  # just use the pre-installed.
)

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "85ffff62a4c22a74dbd98d05da6cf40f497344b3dbf1e1ab0a37ab2a1a6ca014",
    strip_prefix = "rules_docker-0.23.0",
    urls = [
        "https://pai-blade.oss-accelerate.aliyuncs.com/build_deps/rules_docker/rules_docker-v0.23.0.tar.gz",
        "https://github.com/bazelbuild/rules_docker/releases/download/v0.23.0/rules_docker-v0.23.0.tar.gz",
    ],
)

local_repository(
    name = "org_third_party",
    path = "../third_party/",
)

load("@org_third_party//bazel/tensorrt:repo.bzl", "tensorrt_configure")
load("@org_third_party//bazel/cuda_supplement:cuda_supplement_configure.bzl", "cuda_supplement_configure")
load("@org_third_party//bazel/blade_disc_helper:blade_disc_helper_configure.bzl", "blade_disc_helper_configure")
load("//bazel/torch:repo.bzl", "torch_configure", "torch_pybind11_configure")

tensorrt_configure(name = "tensorrt")
cuda_supplement_configure(name = "local_config_cuda_supplement")
torch_configure(name = "local_org_torch")
blade_disc_helper_configure(name = "local_config_blade_disc_helper")

# To load blade_service_common
load("@org_third_party//bazel/blade_service_common:blade_service_common_configure.bzl", "blade_service_common_configure")
blade_service_common_configure(name = "local_config_blade_service_common")
load("@local_config_blade_service_common//:blade_service_common_workspace.bzl", "blade_service_common_workspace")
blade_service_common_workspace()

torch_pybind11_configure(
    name = "pybind11",
    build_file = "@pybind11_bazel//:pybind11.BUILD",
)

local_repository(
    name = "org_tensorflow",
    path = "../tf_community",
)

local_repository(
    name = "org_disc_compiler",
    path = "../tao_compiler",
)

load("@org_third_party//bazel:blade_disc_dnn_workspace.bzl", "blade_disc_dnn_workspace")

blade_disc_dnn_workspace()

new_local_repository(
    name = "onednn",
    build_file = "@local_config_onednn//:onednn.BUILD",
    path = "../tao/third_party/mkldnn"
)

new_local_repository(
    name = "blade_gemm",
    build_file = "@org_third_party//bazel/third_party:blade_gemm.BUILD",
    path = "../../platform_alibaba/blade_gemm"
)

blade_http_archive(
  name = "mlir-hlo",
  sha256 = "ba30ee3f189c9f993cb2de823fdb6ddb41dd2c9145f0b53a958ad4b56e6cb3ee",
  strip_prefix = "mlir-hlo-ac26bdba7a5edfe6060ba5be528b9d20c987297d",
  urls = [
    "https://github.com/tensorflow/mlir-hlo/archive/ac26bdba7a5edfe6060ba5be528b9d20c987297d.zip",
  ],
  patch_file = [
    "//bazel/torch_mlir:disable-simplify-dynamic-gather-to-gather.patch",
    "//bazel/torch_mlir:absl-build-path.patch",
  ]
)

new_local_repository(
    name = "torch-mlir-importer",
    build_file = "@//bazel:torch_mlir/BUILD",
    path = "third_party/torch-mlir"
)

load("@torch-mlir-importer//utils/bazel:configure.bzl", "torch_mlir_configure")

torch_mlir_configure(
  name = "torch-mlir"
)

load("//bazel:platform_alibaba/workspace.bzl", "alibaba_workspace")
alibaba_workspace()

# Initialize TensorFlow's external dependencies.
load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3")

tf_workspace3()

load("@org_tensorflow//tensorflow:workspace2.bzl", "tf_workspace2")

tf_workspace2()

load("@org_tensorflow//tensorflow:workspace1.bzl", "tf_workspace1")

tf_workspace1()

load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0")

tf_workspace0()

load("@org_disc_compiler//build_tools/bazel:workspace.bzl", "disc_compiler_workspace")

disc_compiler_workspace()
